-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GL_TEXTURE_RECTANGLE texture target support #997
Conversation
☔ The latest upstream changes (presumably #995) made this pull request unmergeable. Please resolve the merge conflicts. |
92be058
to
d0ffcd4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit changes the enum ImageData and SourceTexture def.
0ce9f97#diff-9aae73cdde1c142339d62fa040c56ec1R86
0ce9f97#diff-d92392172ea565b8624a34bb15391bccR52
Then we could pass the different external gl handle around the rendering path. Then, we could get the image type in SourceSurface to select the correct shader(We are trying to handle TEXTURE_2D and TEXTURE_RECT).
uniform sampler2D sColor0; | ||
uniform sampler2D sColor1; | ||
uniform sampler2D sColor2; | ||
#else | ||
uniform sampler2DRect sColor0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
macIOSurface should use sampler2DRect
webrender/res/ps_image_rect.fs.glsl
Outdated
|
||
alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize)))); | ||
|
||
oFragColor = vec4(alpha) * texture(sColor0, st); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
textureLod doesn't support Sample2DRect. Use texture() instead.
And the range of each st components are not in [0.0, 1.0]. They are in [0, texture_size.width] and [0, texture_size.height].
@@ -659,6 +662,13 @@ impl Renderer { | |||
options.precache_shaders) | |||
}; | |||
|
|||
let ps_image_rect = try!{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a new shader for textureRect. We could also merge this back to the original image shader. I don't like too much "#ifdef" in the code.
SourceTexture::External(ext_image) => { | ||
match ext_image.image_type { | ||
ExternalImageType::Texture2DHandle => AlphaBatchKind::Image, | ||
ExternalImageType::TextureRectHandle => AlphaBatchKind::ImageRect, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we have "ExternalImageType::TextureRectHandle", use ImageRect shader for this type.
For reference, Gecko appears to be using texture2DRect and sampler2DRect: I would prefer to not add extra shader source files for this (and just |
I'd like to avoid first-class support for texture rectangles in WR. This concept is not supported outside of GL land, so it would make it more difficult to introduce more graphics backends. Instead, I'd like to see as minimal hack as possible to support |
We don't have a choice on OSX as it's the only way to render hardware accelerated video frames as far as I know. |
@nical yes, that's why I said let's hack this in. Doing a compile switch for the shaders is certainly a smaller hack then exposing the rectangles as a valid texture type. |
Ah yes, I agree. And not such a bad hack since the only things that change are the uniform sampler definition and sampling function name. We already have compile time switches for bigger things like transforms. |
Yes, this concept is not supported outside of GL land. But why this is the problem if we try to have more graphics backends? We could just have a panic hint for the new backend if we try to use the non-supported TextureRectHandle feature. And how could we recognize the current usage for texture2d or textureRect without adding the new type of externalImage? That information is required to switch the different shaders for texture2d and textureRect. We might have both usage of texture2d or textureRect at mac platform. So, I extend the external image type into:
0ce9f97#diff-9aae73cdde1c142339d62fa040c56ec1 Most of changes are for these new types updating. |
@JerryShih yeah, having |
Thanks, I will keep working base on the new type "ExternalImageType::TextureRectHandle". The ps_image_rect and ps_image shader will be merged together. And I will use a feature "#ifdef" to switch the different functionality(texture2D and textureRect). |
☔ The latest upstream changes (presumably #1003) made this pull request unmergeable. Please resolve the merge conflicts. |
bf6b689
to
f06cbae
Compare
☔ The latest upstream changes (presumably #966) made this pull request unmergeable. Please resolve the merge conflicts. |
f06cbae
to
6b57949
Compare
panic!("External texture handle should not go through texture_cache."); | ||
} | ||
ExternalImageType::ExternalBuffer => { | ||
let update_op = TextureUpdate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block comes from:
b4e91e1#diff-d52ac938b0c681e0d7bb3f946e47489fL825
panic!("External texture handle should not go through texture_cache."); | ||
} | ||
ExternalImageType::ExternalBuffer => { | ||
let update_op = TextureUpdate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block comes from:
b4e91e1#diff-d52ac938b0c681e0d7bb3f946e47489fL806
webrender/src/resource_cache.rs
Outdated
@@ -651,6 +674,87 @@ impl ResourceCache { | |||
} | |||
} | |||
} | |||
fn update_texture_cache(cached_images: &mut ResourceClassCache<ImageRequest, CachedImageInfo>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is extracted from:
b4e91e1#diff-77cbdf7ba9ebae81feb38a64c21b8454L669
Since there are some "self" mutable borrow problem, this update_texture_cache() becomes static function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: may look better if it's not static
What borrow problems did you encounter? Maybe we can work around them in a cleaner way.
webrender/src/resource_cache.rs
Outdated
texture_cache_id: image_id, | ||
epoch: image_template.epoch, | ||
}); | ||
ExternalImageType::ExternalBuffer => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only call update_texture_cache for ExternalBuffer, Raw and Blob image.
ImageData::ExternalHandle(id) => Some(id), | ||
// raw and externalBuffer are all use resource_cache. | ||
ImageData::Raw(..) | ImageData::ExternalBuffer(..) | ImageData::Blob(..) => None, | ||
let external_image = match image_template.data { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Texture2DHandle, TextureRectHandle => some(ext_image)
Raw, Blob, ExternalBuffer => None
@kvark @nical @glennw
Could you please take a look at this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found no major issues, but got a few things to address preferably.
webrender/res/ps_image.fs.glsl
Outdated
vec2 st = vTextureOffset + ((position_in_tile / vStretchSize) * vTextureSize); | ||
st = clamp(st, vStRect.xy, vStRect.zw); | ||
|
||
alpha = alpha * float(all(bvec2(step(position_in_tile, vStretchSize)))); | ||
|
||
#ifndef WR_FEATURE_TEXTURE_RECT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer having ifdef
path instead of ifndef
webrender/res/ps_image.glsl
Outdated
@@ -2,10 +2,13 @@ | |||
* License, v. 2.0. If a copy of the MPL was not distributed with this | |||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |||
|
|||
// If this is in WR_FEATURE_TEXTURE_RECT mode, the rect and size use non-normalized | |||
// texture coordinates. Otherwise, it's use normalized texture coordinates. Please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix it's use
-> it uses
webrender/res/ps_image.vs.glsl
Outdated
// vUv will contain how many times this image has wrapped around the image size. | ||
#ifndef WR_FEATURE_TEXTURE_RECT | ||
vec2 texture_size = vec2(textureSize(sColor0, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be less of a code change if just texture_size
is branched out, and the rest of the code is uniform
webrender/src/renderer.rs
Outdated
ExternalImageType::Texture2DHandle => TextureTarget::Default, | ||
ExternalImageType::TextureRectHandle => TextureTarget::Rect, | ||
_ => { | ||
panic!("Not a suitable image type."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: actually include the type in the message
webrender/src/resource_cache.rs
Outdated
@@ -651,6 +674,87 @@ impl ResourceCache { | |||
} | |||
} | |||
} | |||
fn update_texture_cache(cached_images: &mut ResourceClassCache<ImageRequest, CachedImageInfo>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add new line before the function
webrender/src/resource_cache.rs
Outdated
@@ -651,6 +674,87 @@ impl ResourceCache { | |||
} | |||
} | |||
} | |||
fn update_texture_cache(cached_images: &mut ResourceClassCache<ImageRequest, CachedImageInfo>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: may look better if it's not static
What borrow problems did you encounter? Maybe we can work around them in a cleaner way.
Review status: 0 of 14 files reviewed at latest revision, 9 unresolved discussions. webrender/res/ps_image.fs.glsl, line 32 at r3 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender/res/ps_image.glsl, line 6 at r3 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender/res/ps_image.vs.glsl, line 37 at r3 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender/src/renderer.rs, line 1673 at r3 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender/src/resource_cache.rs, line 677 at r3 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. Comments from Reviewable |
The error message:
Review status: 0 of 14 files reviewed at latest revision, 9 unresolved discussions. Comments from Reviewable |
6b57949
to
3a3f830
Compare
☔ The latest upstream changes (presumably #1009) made this pull request unmergeable. Please resolve the merge conflicts. |
@JerryShih let (old_data, new_data) = {
let image_template = self.image_templates.get_mut(&request.key).unwrap();
let new_data = image_data.unwrap_or_else(||{
image_template.data.clone()
});
(image_template.data.clone(), new_data)
};
match old_data {
...
} This would contain the borrow of |
Sorry, my test code doesn't show all detail. We should not use the cloned image_template here. It will be updated in update_texture_cache(). |
3a3f830
to
5da747c
Compare
webrender/src/resource_cache.rs
Outdated
fn update_texture_cache(cached_images: &mut ResourceClassCache<ImageRequest, CachedImageInfo>, | ||
texture_cache: &mut TextureCache, | ||
current_frame_id: FrameId, | ||
fn update_texture_cache(&mut self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is another version of update_texture_cache(). This version spends one more "image_templates" hash table lookup, but it turns to a member function.
I still prefer the static function one.
☔ The latest upstream changes (presumably #1004) made this pull request unmergeable. Please resolve the merge conflicts. |
5da747c
to
4c78f6f
Compare
Sorry, rebase again. |
Thanks @JerryShih ! |
@kvark
|
…mage TextureRectHandle.
4c78f6f
to
bbfefcc
Compare
@kvark
|
@JerryShih I see, thanks. The double lookup should be fine (until we get deeper into the optimization stage), given that the relevant hashmap cell is already in the cache by that time. |
📌 Commit bbfefcc has been approved by |
GL_TEXTURE_RECTANGLE texture target support @glennw @kvark @nical @sotaroikeda The hardware video decoder in mac platform is usually decoding the video content into MacIOSurface. The MacIOSurface could just map to an GL_TEXTURE_RECTANGLE gl texture without any uploading. That's good for video playing. These patches try to add a new type of external gl rect image and its corresponding shader. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/997) <!-- Reviewable:end -->
☀️ Test successful - status-travis |
@glennw @kvark @nical @sotaroikeda
The hardware video decoder in mac platform is usually decoding the video content into MacIOSurface. The MacIOSurface could just map to an GL_TEXTURE_RECTANGLE gl texture without any uploading. That's good for video playing.
These patches try to add a new type of external gl rect image and its corresponding shader.
This change is